from django.contrib import admin
from .models import (
    LocalOrder, TransferOrder, AfterSaleOrder, RelocationOrder, 
    CrossOrder, ReturnOrder, InventoryReceiveOrder, RepairOrder,
    UnprocessedOrder, ShippingFeeConfig
)
# Register your models here.

class LocalOrderAdmin(admin.ModelAdmin):
    list_display = [
        'fs_no', 'company_name', 'address1', 'address2', 'phone_number', 
        'attention', 'country', 'postal_code', 'city', 'state', 
        'weight', 'length', 'width', 'height', 'is_delete',
        'shipping_method', 'create_time', 'update_time'
    ]
    ordering = ['-create_time']


class TransferOrderAdmin(admin.ModelAdmin):
    list_display = [
        'fs_no', 'cw_no', 'length', 'width', 'height', 'weight', 'create_time', 'update_time'
    ]
    ordering = ['-create_time']

admin.site.register(LocalOrder, LocalOrderAdmin)
admin.site.register(TransferOrder, TransferOrderAdmin)

@admin.register(ShippingFeeConfig)
class ShippingFeeConfigAdmin(admin.ModelAdmin):
    list_display = ['carrier', 'volume', 'region', 'price', 'is_active', 'create_time']
    list_filter = ['carrier', 'is_active', 'create_time']
    search_fields = ['region']
    ordering = ['carrier', 'volume', 'region']
    list_per_page = 50
    
    fieldsets = (
        ('基本信息', {
            'fields': ('carrier', 'volume', 'region', 'price', 'is_active')
        }),
        ('时间信息', {
            'fields': ('create_time', 'update_time'),
            'classes': ('collapse',)
        }),
    )
    
    readonly_fields = ['create_time', 'update_time']
    
    def get_queryset(self, request):
        return super().get_queryset(request).select_related()